#include "AnaDef.h"
#include "AnaAliDef.h"
#include "IniRun.h"
//#include "AliAnalysisTaskpkRaa.h"

void run(const TString fin)
{
  AliLog::SetGlobalLogLevel(AliLog::kError);

  const TString taskname="pkRaa";
  TChain * esdchain = IniRun(fin, 0x0, kFALSE, kFALSE, kFALSE);

  gROOT->LoadMacro("/u/xlu/.task/pkRaa/AddTask_xlu_pkRaa.C");
  const Long_t r = gROOT->ProcessLine("AddTask_xlu_pkRaa()");
  AliAnalysisTask *task = reinterpret_cast<AliAnalysisTask*>(r);
  if(!task){
    printf("no analysis task!!\n");exit(1);
  }

  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    printf("no mgr!!\n");exit(1);
  }

  // Run the Analysis
  Int_t nentries = 10000000;
  //nentries = 300;//2000;
  if(nentries<1e6){
    printf("\n***************** MYLOG WARNING test mode!! nentries = %d *****************\n\n", nentries);
  }

  if(mgr->InitAnalysis()){  
    TStopwatch timer;
    timer.Start();
    mgr->StartAnalysis("local", esdchain, nentries);
    timer.Stop();
    timer.Print();
  }
}


int main(int argc, char *argv[])
{
  for(int ii=0; ii<argc; ii++){
    printf("%d: %s\n", ii, argv[ii]);
  }
  if(argc!=2){
    printf("argv!=2\n");exit(1);
  }

  run(argv[1]);

  return 0;
}
